<template>
  <!-- <van-nav-bar
    title="注册"
    left-text="返回"
    left-arrow
    @click-left="$router.back()"
  />
  <van-field
    v-model="tel"
    type="tel"
    label="手机号"
    placeholder="请输入11位手机号"
  />
  <van-field
    v-model="password"
    type="password"
    label="密码"
    placeholder="请输入密码"
  />
  <van-field
    v-model="repassword"
    type="password"
    label="密码验证"
    placeholder="请再次输入密码"
  />

  <van-field
    v-model="sms"
    center
    clearable
    label="短信验证码"
    placeholder="请输入短信验证码"
  >
    <template #button>
      <van-button
        size="small"
        @click="send"
        type="primary"
        :disabled="tel.length != 11"
        >发送验证码</van-button
      >
    </template>
  </van-field>
  <van-button :disabled="!flage" round type="danger" @click="submit"
    >确定</van-button
  > -->
  <regist-one-comp></regist-one-comp>
  <!-- <regist-two-comp></regist-two-comp> -->
</template>

<script setup lang="ts">
import RegistOneComp from "@/components/RegistComp/RegistOneComp.vue";
// import RegistTwoComp from "@/components/RegistComp/RegistTwoComp.vue";

// import { ref, computed } from "vue";
// import { showConfirmDialog } from "vant";
// import type { Ref } from "vue";
// import { useRouter } from "vue-router";
// import { MsgCode } from "@/api/api";
// import { CheckCode } from "@/api/api";
// import { UserRegister } from "@/api/api";
// import { CheckPhone } from "@/api/api";

// import { showSuccessToast, showFailToast } from "vant";

// interface IApiCode {
//   code: string;
//   data: number;
//   message: string;
// }

// const router = useRouter();
// const sms: Ref<number | string> = ref("");
// const tel: Ref<string> = ref("");
// const password: Ref<string> = ref("");
// const repassword: Ref<string> = ref("");
// const flage = computed(() => {
//   return tel.value.length === 11 && sms.value && password.value;
// });

// const send = () => {
//   showConfirmDialog({
//     title: "提示",
//     message: `将向手机号${tel.value}发送短信验证码`,
//   })
//     .then(async () => {
//       if (password.value === repassword.value) {
//         const res = (await MsgCode({
//           tel: tel.value as string,
//         })) as unknown as IApiCode;
//         console.log(res);
//         if (res.code === "200") {
//           sms.value = res.data;
//         }
//       } else {
//         showFailToast("请输入同样的密码");
//       }
//     })

//     .catch(() => {
//       console.log("取消发送");
//     });
// };

// const submit = async () => {
//   //校验验证码逻辑
//   const code = await CheckCode({
//     tel: tel.value as string,
//     telcode: sms.value as string,
//   });

//   //注册逻辑
//   const regist = await UserRegister({
//     tel: tel.value as string,
//     password: password.value as string,
//   });

//   //验证手机号是否被注册过
//   const check = await CheckPhone({
//     tel: tel.value as string,
//   });

//   // if (check as unknown as IApiCode.code) {

//   // }

//   if ((code as unknown as IApiCode).code === "200") {
//     if ((regist as unknown as IApiCode).code === "200") {
//       showConfirmDialog({
//         title: "注册成功",
//         message: `注册成功，立即去登录？`,
//       })
//         .then(async () => {
//           router.push("/login");
//         })

//         .catch(() => {
//           console.log("取消去登录");
//         });
//       console.log(regist);
//       console.log(check);
//     } else {
//       showFailToast((regist as unknown as IApiCode).message);
//       console.log(code);
//       console.log(regist);
//     }
//     console.log(code);
//   } else {
//     showFailToast((code as unknown as IApiCode).message);
//     console.log(code);
//     console.log(regist);
//   }
// };
</script>

<style lang="scss" scoped>
.van-cell {
  margin-bottom: 2rem;
  margin-bottom: 3.5rem;
}

.van-nav-bar {
  margin-bottom: 3.5rem;
}

.van-button--round {
  margin-top: 3.5rem;
}
</style>